<template>
	<view class="hobby">
		<an-nav-bar title="兴趣爱好"> </an-nav-bar>
		<view class="tips flex">
			标签最多可选6个，请选择自己的兴趣爱好。
		</view>
		<view class="list">
			<view class="line flex_sw " v-for="(item,index) in list" :key="index" :class="{'check':item.check}"
				@click="selectTag(item)">
				<text>{{item.text}}</text>
			</view>
		</view>
		<view class="bottom flex_center">
			<button @click="submit">确定</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: []
			};
		},
		onLoad() {
			this.$http.get('/appNoAuth/store/massageTechnician/listHobbies').then(res => {
				this.list = res.data.split(',').map(val => {
					return {
						text: val,
						check: false
					}
				})
			})
		},
		methods: {
			selectTag(item) {
				let arr = this.list.filter(val => val.check)
				if (arr.length < 6) {
					item.check = !item.check
				} else {
					uni.showToast({
						title: '最多选择6个标签',
						icon: 'none'
					})
				}
			},
			submit() {
				// 返回上一页并刷新数据方法
				let arr = []
				this.list.forEach(val => {
					if (val.check) arr.push(val.text)

				})
				let pages = getCurrentPages() // 获取页面栈
				let prePage = pages[pages.length - 2] //获取上一页
				prePage.$vm.technicianForm.hobbies = arr.join(',');
				// 返回上一页 delta返回的页面数 如果delta大于现有页面数，则返回首页
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hobby {
		padding: 0 30rpx 120rpx;

		.bottom {
			width: 100%;
			height: 120rpx;
			background: #fff;
			box-shadow: 0 -2rpx 10rpx 0 rgba(0, 0, 0, .1);
			position: fixed;
			left: 0;
			bottom: 0;

			button {
				width: 690rpx;
				height: 80rpx;
				background: linear-gradient(90deg, #d7b075, #aa8050);
				border-radius: 48rpx;
				color: #fff;
				font-size: 30rpx;
				line-height: 80rpx;

				&::after {
					border: none;
				}
			}
		}

		.list {
			.line {
				height: 100rpx;
				border-bottom: 2rpx solid #eee;
				color: #666;
				font-size: 30rpx;
				line-height: 100rpx;
			}

			.check {
				color: #333;

				&::after {
					display: block;
					content: "";
					width: 24rpx;
					height: 16rpx;
					background: url(/static/gou.png) no-repeat;
					background-size: 100% auto;
					margin-right: 30rpx;
				}
			}
		}

		.tips {
			color: #999;
			font-size: 28rpx;
			height: 80rpx;
			border-bottom: 2rpx solid #eee;

			&:before {
				display: block;
				content: "";
				width: 36rpx;
				height: 36rpx;
				background: url(/static/deng.png) no-repeat;
				background-size: 100% auto;
				margin-right: 10rpx;
			}
		}
	}
</style>
